<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
		if(!empty($_SESSION['username']))
		{
			redirect('index.php?c=manage');
		}else{
			$this->load->view('login_login');
		}
	}
	public function checkLogin()
	{
		$userName=getGP('userName');
		$passWord=getGP('passWord');
 		if(empty($userName))
 		{
			alert("请输入账号");
 		}
 		if(empty($passWord))
 		{
			alert("请输入密码","index.php");
 		}
 		if($userName && $passWord){
			$sql ="select * from user where account='".$userName."' and sign='1'";
			if(fetch_count($sql)<=0)
			{
					alert("用户名不正确","index.php");
			}else{
				$user= fetch_one_array($sql);
				if($user['password'] != $passWord){
					alert("账号密码不正确","index.php");
				}else{
					$_SESSION['username']=$user['username'];
					$_SESSION['userid']=$user['id'];
					$_SESSION['account']=$userName;
					$_SESSION['user_type']=$user['user_type'];
                    if($user['user_type'] =="3" || $user['user_type']=="4"){
                        $_SESSION['iduserbrand']=1;
                        $_SESSION['user_token']=$user['token'];
                    }
					redirect("index.php?c=manage");
				}
			}
		}else{
			alert('登录失败',"index.php");
		}
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */